<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>简单任务</legend>
        </fieldset>
        <!-- 示例-970 -->
        <ins class="adsbygoogle" style="display:inline-block;width:970px;height:60px" data-ad-client="ca-pub-6111334333458862" data-ad-slot="3820120620"></ins>

        <form class="layui-form" action="" lay-filter="example">
            <div class="layui-form-item">
                <label class="layui-form-label">任务名称</label>
                <div class="layui-input-block">
                    <input type="text" name="taskname" lay-verify="title" autocomplete="off" placeholder="输入任务名称" class="layui-input">
                </div>
            </div>
			
            <div class="layui-form-item">
                <label class="layui-form-label">IP地址</label>
               <!-- <div class="layui-input-inline"> -->
				<div class="layui-input-block">
                    <input type="text" name="ip" placeholder="以逗号分隔" autocomplete="off" class="layui-input" id="demo" value="" ts-selected="">
                </div>
                <div class="layui-form-mid layui-word-aux"></div>
            </div>


            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">shell 命令</label>
                <div class="layui-input-block">
                    <textarea placeholder="写入单条命令" class="layui-textarea" name="desc"></textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="demo1">立即执行</button>
                </div>
            </div>
        </form>
       
    </div>
</div>

<script>
    layui.use(['form', 'layedit', 'laydate','tableSelect'], function () {
        var form = layui.form,
	     	$ = layui.jquery,
			table = layui.table,
            layer = layui.layer,
            layedit = layui.layedit,
            laydate = layui.laydate;	
			tableSelect = layui.tableSelect
		form.render();	
		
		tableSelect.render({
			elem: '#demo',
			searchKey: 'my',
			checkedKey: 'id',
			searchPlaceholder: '自定义文字和name',
			table: {
				url: 'http://127.0.0.1:8199/task/machinelist',
				cols: [[
					{ type: 'checkbox' },
					{ field: 'ip', title: 'IP', width: 150 },
					{ field: 'node_status', title: '节点状态', width: 90 },
					{ field: 'area', title: '地区', width: 90 },
				]]
			},
			done: function (elem, data) {
				var NEWJSON = []
				layui.each(data.data, function (index, item) {
					NEWJSON.push(item.ip)
				})
				elem.val(NEWJSON.join(","))
			}
		})
        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //监听提交
        form.on('submit(demo1)', function (data) {
            layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            })
			$.ajax({
				type:'post',
				url:'http://127.0.0.1:8199/task/storagetask',
				data: data.field,
				traditional: true,
			})
            return false;
        });
    });
</script>